<template>
	<view class="all bg" v-cloak>
		<u-navbar title="创建视频" bgColor="transparent" autoBack placeholder @rightClick="bgImg={id: '',url: ''}">
			<view class="u-nav-slot" slot="right">
				<view v-show="pageType=='video'" class="closeBox dfx alc" @click="bgImg={id: '',url: ''}">
					移除背景
				</view>
			</view>
		</u-navbar>
		<view class="content">
			<view class="showImg">
				<view class="tip" v-show="!bgImg.url&&!picImg.url">点击下方列表选择</view>
				<image style="top: 0px;z-index: 2" :src="picImg.url" :lazy-load="true"></image>
				<image v-show="bgImg.url" :src="bgImg.url" :lazy-load="true"></image>
			</view>

			<view class="bottom-Box">
				<u-tabs :list="navlist" :current="current" @click="chooseClick"></u-tabs>
				<!-- <tabs :tabs="navlist" @choose="chooseClick"></tabs> -->
				<view class="" v-if="list.length>0">
					<u-scroll-list :indicator="false">
						<view v-for="(item, index) in list" class="imglist" :key="index">
							<view class="text-c" v-show="current==0" @click="setImg(item)">
								<image :src="item.cover"></image>
								<view class="ft13 text-notice">
									{{ item.name }}
								</view>
							</view>
							<view class="" v-show="current!=0" @click="setBg(item)">
								<image :src="item.url"></image>
							</view>
						</view>
					</u-scroll-list>
				</view>
				<view class="text-c" v-else>
					暂无数据
				</view>
			</view>
		</view>

		<view class="btnBox">
			<view class="btn btn1 cfff" @click="create">
				去创建声音文案
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageType: 'live',
				navlist: [{
					name: '数字人'
				}],
				showSize: false,
				switchVal: false,
				imageData: [],
				bgData: [],
				list: [],
				picImg: {
					id: '',
					url: ''
				},
				bgImg: {
					id: '',
					url: ''
				},
				sound: {
					id: '',
					title: ''
				},
				current: 0,
			};
		},
		onLoad(e) {
			if (e?.id == 'live') {
				this.pageType = 'live'
				this.navlist = [{
					name: '数字人'
				}]
			} else {
				this.title = '短视频创作'
				this.navlist = [{
					name: '数字人'
				}, {
					name: '系统背景'
				}, {
					name: '自定义'
				}, {
					name: 'AI背景'
				}]
			}
			console.log(this.bgImg);
			this.initData()
		},
		methods: {
			initData() {
				this.$api.get_image_list().then(res => {
					this.imageData.push(...res.data.list)
					console.log(this.imageData);
					this.list.push(...this.imageData)
					this.setImg(this.imageData[0])
				})
				if (this.pageType == 'video') {
					this.$api.get_backgrounds({
						type: 1
					}).then(res => {
						this.bgData.push(...res.data.list)
					})
				}
			},
			chooseClick(e) {
				console.log(e.index);

				this.current = e.index || e
				this.list = []
				this.list = e.index == 0 ? this.imageData : this.getBg()
			},
			setImg(e) {
				this.picImg = {
					id: e.id,
					url: e.cover_png
				}
			},
			navTo() {
				uni.navigateTo({
					url: '/pages/data/add'
				})
			},
			create() {
				if (!this.picImg.id) {
					uni.$u.toast('请选择数字人形象！')
					return;
				}
				this.$tools.navTo('index/videoList/audioText')
				let data = {
					image_id: this.picImg.id,
					sound_id: this.sound.id,
					background_id: this.bgImg.id || '',
					type_s: 1
				}
				this.$http.submit_video(data).then(res => {
					uni.$u.toast(res.msg)
					if (res.code = 200) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
				})

			}
		},

	};
</script>

<style lang="scss" scoped>
	.all {
		width: 100vw;
		height: 100vh;
		// background-color: #F8F8F8;
		background-size: 100% 100vh !important;

		.content {
			padding: 30rpx;

			.showImg {
				margin: 0 auto;
				width: 540rpx;
				height: 960rpx;
				overflow: hidden;
				text-align: center;
				background-color: #ffffff;
				border-radius: 8px;

				.tip {
					position: relative;
					top: 180px;
				}

				image {
					width: 540rpx;
					height: 960rpx;
					position: relative;
					top: -101%;
					z-index: 1;
				}
			}
		}

		.btnBox {
			position: fixed;
			bottom: 0;
			width: 100vw;
			left: 0vw;
			// background: #f7fbfe;
			z-index: 10;
			display: flex;
			justify-content: space-between;

			.btn {
				margin: 20rpx auto;
				width: 80vw;
				background: #f5f7fa;
				border-radius: 20rpx;
				text-align: center;
				height: 80rpx;
				line-height: 80rpx;
			}

			.btn1 {
				background-color: #6a8bff;
			}
		}

		.bottom-Box {
			background: #fff;
			border-radius: 8px;
			margin-top: 10px;
			padding: 10rpx 20rpx;
			// box-shadow: 1px 2px 10px rgba(20, 111, 255, 0.09);

			.imglist {
				// margin-top: -10rpx; 

				image {
					width: 99rpx;
					height: 176rpx;
					border-radius: 4px;
					margin-right: 18rpx;
				}

				image:last-child {
					margin-right: 0;
				}
			}
		}
	}

	/deep/.uicon-trash {
		font-size: 36rpx !important;
	}
</style>